// DlgSetAccount.cpp : 实现文件
//

#include "AIPanelDataCSI.h"

#include <uam/UserAccountManager.h>

#include <QColor>
#include <QFontMetrics>
#include <QPainter>
#include <QStylePainter>

#include "../StringResource.h"

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// class CAIPanelDataCSI
CAIPanelDataCSI::CAIPanelDataCSI() {
  m_strType = tr("CSI");
  m_imgSuccess = ImgMgr::instance().image("guiframe_icon_tips_success");
}

CAIPanelDataCSI::~CAIPanelDataCSI() {}

void CAIPanelDataCSI::Init() { m_nHeight = (24 + 8) * 2; }

void CAIPanelDataCSI::Draw(QPainter* painter, int top) {
  bool hasCSIRight = SSUserAccountManager::instance().GetCSIAuthorityFlag();
  QColor brHead = QColor(230, 179, 66);
  ;
  QColor brFront = NAME_COLOR("TextNormal");

  QString strTemp = NewStringTable::strAIPanelDataCSI(0);  // 数据权限 - 中证
  int nGap = 8;

  // 数据权限 - 中证
  int X = nGap;
  int Y = 0;

  QRect r = rect();
  QRect textRect = QRect(X, Y, r.right() - X, Y + 24);
  painter->setFont(m_lfHead);
  painter->setPen(QPen(brHead));
  painter->drawText(textRect, strTemp,
                    QTextOption(Qt::AlignLeft | Qt::AlignVCenter));

  X += 24;
  Y += 24 + nGap;
  int nMaxWidth = 1000;
  int nImgHeight = 20;
  if (m_imgSuccess) nImgHeight = m_imgSuccess->height();

  painter->setFont(m_lfContent);
  if (hasCSIRight) {
    if (m_imgSuccess) {
      int x = X + (24 - nImgHeight) / 2;
      int y = Y + (24 - nImgHeight) / 2;
      QPixmap m_tipssuccess = QPixmap::fromImage(*m_imgSuccess);
      painter->drawPixmap(x, y, m_tipssuccess);
      X += 24 + 1;
    }
    strTemp = NewStringTable::strAIPanelDataCSI(1);  // 您已获得中证数据权限。
    textRect = QRect(X, Y, nMaxWidth, 24);
    painter->setPen(QPen(brFront));
    painter->drawText(textRect, strTemp,
                      QTextOption(Qt::AlignLeft | Qt::AlignVCenter));
  } else {
    // 无权限
    strTemp = NewStringTable::strAIPanelDataCSI(2);  // 您暂未开通中债数据权限
    QFontMetrics fontMetrics = QFontMetrics(m_lfContent);
    int nFontWidth = fontMetrics.width(strTemp);

    textRect = QRect(X, Y, nMaxWidth, 24);
    painter->setPen(QPen(brFront));
    painter->drawText(textRect, strTemp,
                      QTextOption(Qt::AlignLeft | Qt::AlignVCenter));

    X += nFontWidth;
    strTemp = NewStringTable::strAIPanelDataCSI(3);  // NOT
    fontMetrics = QFontMetrics(m_lfContent);
    nFontWidth = fontMetrics.width(strTemp);

    textRect = QRect(X, Y, nMaxWidth, 24);
    painter->setPen(QPen(brHead));
    painter->drawText(textRect, strTemp,
                      QTextOption(Qt::AlignLeft | Qt::AlignVCenter));

    X += nFontWidth;
    strTemp = NewStringTable::strAIPanelDataCSI(
        4);  // been authorized to access CSI data.

    textRect = QRect(X, Y, nMaxWidth, 24);
    painter->setPen(QPen(brFront));
    painter->drawText(textRect, strTemp,
                      QTextOption(Qt::AlignLeft | Qt::AlignVCenter));
  }
}

void CAIPanelDataCSI::paintEvent(QPaintEvent* event) {
  QStylePainter painter(this);
  Draw(&painter, 0);
}
